import com.ll.drissonPage.page.ChromiumPage;
import com.ll.drissonPage.units.listener.DataPacket;

import java.text.ParseException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;

public class PersonService1 {
    private static String url = "https://weibo.com/at/weibo";
    private static String like = "https://weibo.com/like/inbox";
    private static String comment = "https://weibo.com/comment/inbox";

    public static void main(String[] args) throws InterruptedException, ParseException {
        ChromiumPage page = openPerson();
        getAtData(page);
        page.close();

    }

    private static List<Object> getAtData(ChromiumPage page) throws InterruptedException {
        page.listen().start("ajax/statuses/mentions");
        TimeUnit.MILLISECONDS.sleep(1000);
        page.get(url);
        List<Object> result = new ArrayList<>();
        List<DataPacket> waits = page.listen().waits();
        page.listen().stop();
        for (DataPacket wait : waits) {
            System.out.println(wait.response().body().toString());
        }
        return result;
    }

    /**
     * 打开你的个人主页
     *
     * @return
     */
    public static ChromiumPage openPerson() {
        ChromiumPage page = ChromiumPage.getInstance();
        page.set().scroll().smooth(false);
        return page;
    }

    /**
     *
     */

    private static void loadMore(int pageNum, ChromiumPage page) throws InterruptedException {
        for (int i = 0; i < pageNum; i++) {
            TimeUnit.SECONDS.sleep(1);
            page.scroll().toBottom();
            TimeUnit.SECONDS.sleep(1);
        }
    }

    private static void loadMore(ChromiumPage page) throws InterruptedException {
        page.scroll().toBottom();
        TimeUnit.SECONDS.sleep(1);

    }

    public static boolean isStringToday(String a) {
        for (char c : a.toCharArray()) {
            if (!Character.isDigit(c)) {
                return true;
            }

        }
        return false;
    }

    /**
     * 判断日期是否再今天之内
     *
     * @param date
     * @return
     */
    public static boolean isToday(String date) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
        LocalDateTime dateTimeToCheck = LocalDateTime.parse(date, formatter); // 将字符串转换为LocalDateTime对象

        LocalDate today = LocalDate.now(); // 获取今天的日期
        LocalDateTime startOfToday = LocalDateTime.of(today, LocalTime.MIN); // 今天的开始时间
        LocalDateTime endOfToday = LocalDateTime.of(today, LocalTime.MAX); // 今天的结束时间

        if (dateTimeToCheck.isEqual(startOfToday) ||
            (dateTimeToCheck.isAfter(startOfToday) && dateTimeToCheck.isBefore(endOfToday)) ||
            Pattern.compile("[\\u4e00-\\u9fa5]").matcher(date).find()) {
            return true;
        } else {
            return false;
        }
    }

}
